Calendar#{extends 'simpleTemplate.html' /}
<title>&{'Calendar_header'}</title>
<script>
    $(function () {
        $("#sortable1, #sortable2").sortable().disableSelection();
        var $tabs = $("#tabs").tabs();
        var $tab_items = $("ul:first li", $tabs).droppable({
            accept: ".connectedSortable li",
            hoverClass: "ui-state-hover",
            drop: function (event, ui) {
                var $item = $(this);
                var $list = $($item.find("a").attr("href")).find(".connectedSortable");
                ui.draggable.hide("slow", function () {
                    $tabs.tabs("option", "active", $tab_items.index($item));
                    $(this).appendTo($list).show("slow");
                    console.log('list: ' + $tab_items.index($item));
                    console.log($(this).find("span").attr("id"));
                    console.log($(this).find("span").text());

                });
            }
        });
    });
</script>

<style type='text/css'>

    body {
        margin-top: 40px;
        text-align: center;
        font-size: 14px;
        font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
    }

    #wrap {
        width: 1100px;
        margin: 0 auto;
    }

    #external-events {
        float: left;
        width: 150px;
        padding: 0 10px;
        border: 1px solid #ccc;
        background: #eee;
        text-align: left;
    }

    #external-events h4 {
        font-size: 16px;
        margin-top: 0;
        padding-top: 1em;
    }

    .external-event {
        /* try to mimick the look of a real event */
        margin: 10px 0;
        padding: 2px 4px;
        background: #3366CC;
        color: #fff;
        font-size: .85em;
        cursor: pointer;
    }

    #external-events p {
        margin: 1.5em 0;
        font-size: 11px;
        color: #666;
    }

    #external-events p input {
        margin: 0;
        vertical-align: middle;
    }

    #calendar {
        float: left;
        width: 800px;
    }

</style>

<style>

    #tabs li {
        margin: 0 5px 5px 5px;
        padding: 5px;
        font-size: 0.7em;
        width: 130px;
    }

</style>

<script type='text/javascript'>
    event = { };
    $(document).ready(function () {


        /* initialize the external events
        -----------------------------------------------------------------*/

        $('#external-events div.external-event').each(function () {

            // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
            // it doesn't need to have a start or end
            var eventObject = {
                title: $.trim($(this).text()) // use the element's text as the event title
            };

            // store the Event Object in the DOM element so we can get to it later
            $(this).data('eventObject', eventObject);

            // make the event draggable using jQuery UI
            $(this).draggable({
                zIndex: 999,
                revert: true,      // will cause the event to go back to its
                revertDuration: 0  //  original position after the drag
            });

        });


        /* initialize the calendar
        -----------------------------------------------------------------*/

        $('#calendar').fullCalendar({

            monthNames: ["&{'Calendar_january'}", "&{'Calendar_february'}", "&{'Calendar_march'}", "&{'Calendar_april'}",
                "&{'Calendar_may'}", "&{'Calendar_june'}", "&{'Calendar_july'}", "&{'Calendar_august'}",
                "&{'Calendar_september'}", "&{'Calendar_october'}", "&{'Calendar_november'}", "&{'Calendar_december'}"],

            monthNamesShort: ["&{'Calendar_jan'}", "&{'Calendar_feb'}", "&{'Calendar_mar'}", "&{'Calendar_apr'}",
                "&{'Calendar_may'}", "&{'Calendar_jun'}", "&{'Calendar_jul'}", "&{'Calendar_aug'}",
                "&{'Calendar_sep'}", "&{'Calendar_oct'}", "&{'Calendar_nov'}", "&{'Calendar_dec'}"],

            dayNames: ["&{'Calendar_sunday'}", "&{'Calendar_monday'}", "&{'Calendar_tuesday'}", "&{'Calendar_wednesday'}",
                "&{'Calendar_thursday'}", "&{'Calendar_friday'}", "&{'Calendar_saturday'}"],

            dayNamesShort: ["&{'Calendar_sun'}", "&{'Calendar_mon'}", "&{'Calendar_tue'}", "&{'Calendar_wed'}",
                "&{'Calendar_thu'}", "&{'Calendar_fri'}", "&{'Calendar_sat'}"],

            buttonText: {
                today: "&{'Calendar_today'}",
                month: "&{'Calendar_month'}",
                week: "&{'Calendar_week'}",
                day: "&{'Calendar_day'}"
            },


            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },


            editable: true,
            droppable: true, // this allows things to be dropped onto the calendar !!!
            drop: function (date, allDay) { // this function is called when something is dropped

                // retrieve the dropped element's stored Event Object
                var originalEventObject = $(this).data('eventObject');

                // we need to copy it, so that multiple events don't have a reference to the same object
                var copiedEventObject = $.extend({}, originalEventObject);

                // assign it the date that was reported
                copiedEventObject.start = date;
                copiedEventObject.allDay = allDay;

                // render the event on the calendar
                // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
                $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
                event.name = $(copiedEventObject).attr("title");
                event.id = $(copiedEventObject).attr("_id");
                event.year = date.getFullYear();
                event.month = date.getMonth() + 1;
                event.day = date.getDay();


                console.log(event);
            },
            selectable: true,
            selectHelper: true,
            select: function (start, end, allDay) {
                var title = prompt('&{'Calendar_event_title'}');
                event.name = title;

                if (title) {
                    $('#calendar').fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                end: end,
                                allDay: allDay
                            },
                            true // make the event "stick"
                    );
                    $.get("/createEvent",
                            {
                                "title": title,
                                "content": title,
                                "dateOfBeginning": start,
                                "dateOfEnding": end
                            }
                    );
                    return;
                }
                <!--$('#calendar').fullCalendar('select');-->
            }
        });


    });

</script>

<div class="content">

    <div class="content-header">
        <h2>&{'Calendar'}</h2>
    </div>

    <div class="content-body">
        <div id='wrap'>
            <div id='external-events'>
                <h4>&{'Calendar_planning_events'}</h4>

                <div class='external-event' href="#myModal" role="button" class="btn"
                     data-toggle="modal">&{'Calendar_add_event'}</div>
            </div>

            <div id='calendar'></div>

            <div style='clear:both'></div>

        </div>
    </div>

    <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">

        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">&{'Calendar_members'}</h3>
        </div>

        <div class="modal-body">
            <div id="tabs">
                <ul>
                    <li><a href="#tabs-1">&{'Calendar_available_members'}</a></li>
                    <li><a href="#tabs-2">&{'Calendar_assigned_members'}</a></li>
                </ul>
                <div id="tabs-1">
                    <ul id="sortable1" class="connectedSortable ui-helper-reset" class="contact-list">
                        <li class="ui-state-default"><img class="contact-item-object" style="width: 16px; height: 16px;"
                                                          src="img/user-thumb-mini.jpg"> <span
                                id="01">Лейла Халикова</span></li>
                        <li class="ui-state-default"><img class="contact-item-object" style="width: 16px; height: 16px;"
                                                          src="img/user-thumb-mini.jpg"> <span
                                id="02">Андрей Никулин</span></li>
                        <li class="ui-state-default"><img class="contact-item-object" style="width: 16px; height: 16px;"
                                                          src="img/user-thumb-mini.jpg"> <span
                                id="03">Семён Ёлкин</span></li>
                    </ul>
                </div>
                <div id="tabs-2">
                    <ul id="sortable2" class="connected`Sortable ui-helper-reset">
                        <li class="ui-state-highlight"><img class="contact-item-object"
                                                            style="width: 16px; height: 16px;"
                                                            src="img/user-thumb-mini.jpg"> <span id="11">Алексей Родионов</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">&{'Calendar_close'}</button>
            <button class="btn btn-primary">&{'Calendar_save_changes'}</button>
        </div>

    </div>

</div>